
/*
 * @Autor: Mr Lu
 * @Version: 1.0
 * @Date: 2019-12-03
 * @LastEditors: OBKoro1
 * @LastEditTime: 2019-12-03
 * @Description:  TaskModeSelect
 */
 <template>
  <div id="TaskModeRealMeasure" class="p-box">
    <div class="p-return" style="margin-bottom:0;box-shadow:none">
      <mu-appbar color="primary" class="lan-header" style="box-shadow:none">
        <mu-button icon slot="left" v-close>
          <i class="iconfont angle-left iconangle-left"></i>
          <span class="lan-header-back">返回</span>
        </mu-button>实测实量
        <mu-button icon slot="right" @click="showFilter">
          <i class="iconfont iconshaixuan4"></i>
        </mu-button>
        <!-- <div slot="right" class="rightContent">
          <mu-button icon @click="scanCode">
            <i class="iconfont iconsaoma"></i>
          </mu-button>
         
        </div>-->
      </mu-appbar>
      <mTabs v-model="active" :tabList="tabList" position="center" />
    </div>
    <div class="p-content">
      <MeasureArea
        v-if="active==1"
        ref="MeasureList"
        @showAddTask="showAddTask"
        :currentProject="currentProject"
        :params="listParams"
      />
      <MeasureList v-else ref="MeasureList" :listParams="listParams" />
    </div>
    <div class="p-footer" v-power="'measureTaskAdd'">
      <div class="flex">
        <div class="flex-1">
          <mu-button full-width color="primary" @click="showAddTask(null)">新建点位</mu-button>
        </div>
      </div>
    </div>
    <Org
      ref="org"
      v-model="org"
      @change="orgChange"
      :open="openOrg"
      title="选择项目"
      orgType="currOrgProject"
      @close="closeOrgDialog"
      @confirm="confirmOrgDialog"
    ></Org>
    <dialogFilter ref="dialogFilter" @searchList="initPage" :currentProject="currentProject" />
    <dialogAddTask
      ref="dialogAddTask"
      :currentProject="currentProject"
      @searchList="afterProjectChange"
    />
  </div>
</template>

<script>
import mTabs from "@/tabs/mTabs";
import Org from "@/select/org/Org.vue";
import MeasureArea from "@/realMeasureModule/taskMode/taskModeRealMeasure/MeasureArea";
import MeasureList from "@/realMeasureModule/taskMode/taskModeRealMeasure/MeasureList";
import dialogFilter from "@/realMeasureModule/taskMode/taskModeRealMeasure/dialogFilter";
import dialogAddTask from "@/realMeasureModule/taskMode/taskModeRealMeasure/dialogAddTask";
import Search from "@/search/Search.vue";
export default {
  name: "TaskModeRealMeasure",
  components: {
    mTabs,
    Org,
    MeasureArea,
    MeasureList,
    dialogAddTask,
    dialogFilter
  },
  props: {},
  data() {
    return {
      active: 1,
      openOrg: false,
      currentProject: {
        id: "",
        name: ""
      },
      listParams: {
        startTime: "",
        endTime: "",
        id: "",
        name
      },
      org: [
        {
          label: "",
          value: "",
          disabled: false,
          checked: false,
          hasChecked: true,
          hasChildren: true
        }
      ],
      tabList: [{ id: "1", name: "区域" }, { id: "2", name: "列表" }],
      selected: 1,
      tree: {
        defaultProps: {
          id: "orgId",
          name: "orgName",
          children: "children"
        },
        clickableConditions: {
          all: {
            //所有的是否可以点击
            enable: false
          },
          part: {
            //部分的可以点击的条件
            prop: "orgType",
            value: [1]
          }
        },
        data: []
      },
      list: {
        data: []
      }
    };
  },
  computed: {},
  // beforeRouteEnter(to, from, next) {
  //   next(vm => {
  //     if (from.name == "TaskModeRealMeasure") {
  //       vm.openOrg = true;
  //     } else {
  //       vm.openOrg = true;
  //     }
  //   });
  // },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (from.name == "StartEdit") {
        vm.$nextTick(() => {
          vm.$refs.dialogAddTask.openMe();
        });
      }
    });
  },
  created() {
    this.org = [
      {
        label: this.$A.GS("orgInfo")["orgName"],
        value: this.$A.GS("orgInfo")["orgId"],
        disabled: false,
        checked: false,
        hasChecked: true,
        hasChildren: true
      }
    ];
    if (this.$A.GS("orgInfo")["type"] == 1) {
      this.openOrg = false;
      this.currentProject = {
        id: this.$A.GS("orgInfo")["orgId"],
        name: this.$A.GS("orgInfo")["orgName"]
      };

      this.listParams = Object.assign(this.listParams, this.currentProject);
    } else {
      this.openOrg = true;
    }
  },
  mounted() {},
  watch: {},
  methods: {
    returnHome() {
      this.$router.replace({
        name: "RealMeasure"
      });
    },
    scanCode() {
      wx.ready(function() {
        wx.checkJsApi({
          jsApiList: ["invoke", "scanQRCode"], // 需要检测的JS接口列表，所有JS接口列表见附录2,
          success: function(ress) {
            // 以键值对的形式返回，可用的api值true，不可用为false
            // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
          }
        });
        wx.invoke("enterpriseVerify", {}, function(res) {
          // alert(JSON.stringify(res));
        });
        wx.scanQRCode({
          desc: "scanQRCode desc",
          needResult: 0, // 默认为0，扫描结果由企业微信处理，1则直接返回扫描结果，
          scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是条形码（一维码），默认二者都有
          success: function(res) {
            // 回调
            console.log(res);
          },
          error: function(res) {
            if (res.errMsg.indexOf("function_not_exist") > 0) {
              alert("版本过低请升级");
            }
          }
        });
      });
    },
    initPage(params) {
      this.currentProject = {
        id: params.projectId,
        name: params.projectName
      };
      this.listParams = Object.assign(
        { startTime: params.startTime, endTime: params.endTime },
        this.currentProject
      );
    },
    afterProjectChange() {
      if (this.active == 1) {
        //区域
      } else {
        //列表
        this.$nextTick(() => {
          this.$refs.MeasureList.refresh();
        });
      }
    },
    orgChange(ev) {
      this.currentProject = {
        id: ev[0].value,
        name: ev[0].label
      };
      this.listParams = Object.assign(this.listParams, this.currentProject);
    },
    changeProject(data) {},
    closeOrgDialog() {
      this.$router.back();
    },
    confirmOrgDialog() {
      this.openOrg = false;
    },
    skipPage(item) {},
    tabChange() {},
    showFilter() {
      this.$refs.dialogFilter.init();
    },
    showAddTask(areaObj) {
      this.$refs.dialogAddTask.init(areaObj);
    }
  },
  destroyed() {}
};
</script>
<style lang="less">
#TaskModeRealMeasure {
  .mu-appbar-right {
    position: relative;
    .rightContent {
      position: absolute;
      left: -20px;
      width: 200px;
      .mu-button:last-child {
        position: relative;
        left: -20px;
      }
    }
  }
  .p-content {
    #Area {
      margin-top: 0.1rem;
    }
  }
}
</style>
